import axios from 'axios';
import nprogress from 'nprogress';
import 'nprogress/nprogress.css';

// 创建axios实例
const requests = axios.create({
  // axios中请求配置有baseURL选项，表示请求URL公共部分
  baseURL: "/mock",
  // 超时
  timeout: 5000,
});

// request拦截器
requests.interceptors.request.use((config) => {
    nprogress.start()

    console.log(config, "request拦截器")

    return config
});

// 响应拦截器
requests.interceptors.response.use(
    (res) => {
        nprogress.done()
        console.log(res, "响应拦截器")
        return res.data.data
    },
    (error) => {
        return Promise.reject(new Error('faile'))
    }
)

// 对外暴露
export default requests